package com.example.javademo;

import android.os.Bundle;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class TextActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_text);

        // 设置窗口插入监听
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 获取跑马灯TextView并设置选中状态
        TextView marqueeText = findViewById(R.id.textViewMarquee);
        marqueeText.setSelected(true);  // 这是关键，启用跑马灯效果

        // 设置触摸监听确保获取焦点
        marqueeText.setOnClickListener(v -> v.setSelected(true));
    }

    @Override
    protected void onResume() {
        super.onResume();
        // 确保每次Activity恢复时都重新激活跑马灯
        TextView marqueeText = findViewById(R.id.textViewMarquee);
        marqueeText.setSelected(true);
    }
}